﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CarLoanSystem
{
    public partial class panelReportIncome : UserControl
    {
        public panelReportIncome()
       {
            InitializeComponent();
            genGridview();
        }

        private void genGridview()
        {
            // gen Grideview
            gvIncome.AutoGenerateColumns = false;

            //Set Columns Count
            gvIncome.ColumnCount = 5;

            //Add Columns
            gvIncome.Columns[0].Name = "YEAR1";
            gvIncome.Columns[0].HeaderText = "ปี";
            gvIncome.Columns[0].DataPropertyName = "YEAR1";
            gvIncome.Columns[0].Width = 73;

            gvIncome.Columns[1].Name = "PRINCIPLE";
            gvIncome.Columns[1].HeaderText = "ยอดเงินที่ปล่อย";
            gvIncome.Columns[1].DataPropertyName = "PRINCIPLE";
            gvIncome.Columns[1].Width = 130;

            gvIncome.Columns[2].Name = "PAY";
            gvIncome.Columns[2].HeaderText = "ยอดชำระคืน";
            gvIncome.Columns[2].DataPropertyName = "PAY";
            gvIncome.Columns[2].Width = 130;

            gvIncome.Columns[3].Name = "PROFIT";
            gvIncome.Columns[3].HeaderText = "กำไร";
            gvIncome.Columns[3].DataPropertyName = "PROFIT";
            gvIncome.Columns[3].Width = 130;

            gvIncome.Columns[4].Name = "LOSS";
            gvIncome.Columns[4].HeaderText = "ขาดทุน";
            gvIncome.Columns[4].DataPropertyName = "LOSS";
            gvIncome.Columns[4].Width = 130;

            // end gen gridview
            //gvPayment.DataSource = LoadReportIncome();
        }

        private DataTable LoadReportIncome()
        {
            DataTable dt = DAL.ReportInfoDAL.LoadAllIncom(this.txtStartYear.Text, this.txtEndYear.Text);
            return dt;
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (this.txtStartYear.Text != "")
            {
                gvIncome.DataSource = LoadReportIncome();
            }
            else 
            {
                MessageBox.Show("กรุณาระบุปีเริ่มต้น", "ออกรายงาน");
            }
        }

        private void btnReport_Click(object sender, EventArgs e)
        {

            ShowReportAllIncom s = new ShowReportAllIncom(LoadReportIncome());
            s.ShowDialog();
        }
    }
}